//
// Created by 下次一定 on 2021/9/26.
//

/*
 *分组背包
 * */

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110;
int n, m;
int f[N];

int v[N][N], w[N][N],s[N];

int main() {
    cin >> n >> m;
    /* n 组   每组s[i]个*/
    for (int i = 1; i <= n; i++){
        cin >> s[i];
        for (int j = 0; j < s[i]; j ++ )
            cin >> w[i][j] >> v[i][j];
    }

    for (int i = 1; i <= n; i ++ ){
        for (int j = m; j >= 0 ; j --){
            for (int k = 0; k < s[i]; k++){
                if(w[i][k] <= j )
                    // 同一个位置 会被组内的元素替换掉
                    f[j] = max(f[j],f[j - w[i][k]] + v[i][k]);
            }
        }
    }
    cout << f[m] << endl;

}